package com.luhuiguo.gwt.security.server;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.AuthenticationException;

import com.luhuiguo.gwt.security.exception.GWTAccessDeniedException;
import com.luhuiguo.gwt.security.exception.GWTAuthenticationException;
import com.luhuiguo.gwt.security.exception.GWTSecurityException;

/**
 * 
 * @author LuHuiguo
 * @version $Id: SecurityExceptionFactory.java 3 2009-12-14 06:18:57Z luhuiguo $
 */
public class SecurityExceptionFactory {
    public static GWTSecurityException get(final RuntimeException springException) {
        GWTSecurityException gwtException = null;
        if (springException instanceof AccessDeniedException) {
            gwtException = new GWTAccessDeniedException(springException.getMessage(),
                    springException);
        } else if (springException instanceof AuthenticationException) {
            gwtException = new GWTAuthenticationException(
                    springException.getMessage(), springException);
        } else {
            gwtException = new GWTSecurityException(springException
                    .getMessage(), springException);
        }
        return gwtException;
    }
}
